package org.dawning.shop.common.utils;

import lombok.extern.log4j.Log4j;
import org.dawning.shop.common.vo.CategoryAttribute;

import java.util.List;

/**
 * Created by L on 2017/6/16.
 */
@Log4j
public class GenerateSku {


    /**
     * 生成SKU信息
     * SKU信息格式：商品id/商品属性的code/属性code/...
     * @param productId
     * @param categoryAttributeList
     * @return
     *
     *
     * 是否与必要将所有属性拼接进行重新计算
     */
    public static String generateSku(String productId, List<CategoryAttribute> categoryAttributeList) {
        try {
            StringBuilder stringBuilder = new StringBuilder(productId);
            if(categoryAttributeList!=null && categoryAttributeList.size()>0){
                for (CategoryAttribute attribute :categoryAttributeList) {
                    stringBuilder.append("|");
                    stringBuilder.append(attribute.getTypeCode());
                    stringBuilder.append(attribute.getAttributeCode());
                }
            }
            return stringBuilder.toString();
        } catch (Exception e) {
            log.info("error", e);
            return null;
        }
    }
}
